package com.karina.visualization.chart.component;

import com.karina.visualization.chart.model.ChartModel;
import com.karina.visualization.chart.skins.ChartPaneSkin;

abstract public class CoordinateChart<Model extends ChartModel<DataType>, DataType>
		extends ChartBase<Model, DataType> {

	private XAxis xaxis;

	private YAxis yaxis;

	private static final int MARGIN = 20;

	protected CoordinateChart(Model model, ChartPaneSkin<Model> skin) {
		super(model, skin);
	}

	public void setOrigionalXY(int origionalX, int origionalY) {
		getContext().setCoordinateXY(origionalX, origionalY);
	}

	void setXaxis(XAxis xaxis) {
		this.xaxis = xaxis;
		addChild(xaxis);
	}

	protected XAxis getXaxis() {
		return xaxis;
	}

	@Override
	public void play(int duration) {
		caculateChartObjectModelProperties();

		super.play(duration);
		getXaxis().enableEffect(enableEffect);
		getYaxis().enableEffect(enableEffect);
		getXaxis().play(duration);
		getYaxis().play(duration);
	}

	void setYaxis(YAxis yaxis) {
		this.yaxis = yaxis;
		addChild(yaxis);
	}

	protected YAxis getYaxis() {
		return yaxis;
	}

	@Override
	protected boolean next() {

		if (!super.next()) {
			yaxis.next();
			xaxis.next();
			return false;
		} else {
			yaxis.next();
			xaxis.next();
			return true;
		}

	}

	@Override
	protected void caculateChartObjectProperties() {
		super.caculateChartObjectProperties();
		getXaxis().getData().setTextMargin(MARGIN);
		getYaxis().getData().setTextMargin(MARGIN);
		setSeriesMargin(MARGIN, MARGIN);
		setTextMargin(MARGIN, MARGIN);
	}
}
